/*
 * @Description: 登录接口
 * @version: V_00.00
 * @Company: SMD
 * @Author: Nick_Yang
 * @Date: 2018-12-10 17:34:04
 * @LastEditors: Nick_Yang
 * @LastEditTime: 2018-12-18 11:56:24
 */

var express = require('express');
var router = express.Router();
var API = require('../utils/mysql.js');

router.post('/', (req, res, next) => {
  var json = req.body || {};
  var Api = new API(req, res, next);

  Api.get('user', `user_name = "${json.username}"`).then(data => {
    console.log(data);
    if (data.length < 1) {
      res.end(JSON.stringify({
        code: 304,
        msg: '用户名不存在'
      }));
    }
    data.some((item) => {
      return item.password === json.password;
    }) ?
    res.end(JSON.stringify({
      code: 200,
      data: [],
      msg: '登录成功'
    })) :
    res.end(JSON.stringify({
      code: 303,
      msg: '密码错误'
    }));
  });
});





module.exports = router;